package Test;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import Interact.Interface;
import Tool.Tool;

public class AppBody extends QuestionBody {
	/** 题目描述 */
	private String content;
	/** 参考答案 */
	private String reference;		

	public AppBody(){
		this(0, null, 0, 0, "", "");
	}
	public AppBody(int id, Course course, int grade, int teacherID, String cont, String ref){
		super(id, course, grade, teacherID);
		this.content = cont;
		this.reference = ref;
	}
	
	@Override
	public void toBytes(OutputStream out) throws IOException {
		getIllustration().toBytes(out);
		Tool.writeString(content, out);
		Tool.writeString(reference, out);
	}
	
	@Override
	public void fromBytes(InputStream in) throws IOException {
		getIllustration().fromBytes(in);
		content = Tool.readString(in);
		reference = Tool.readString(in);
	}

	@Override
	public int getType() {
		return App.TYPE;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getReference() {
		return reference;
	}

	public void setReference(String reference) {
		this.reference = reference;
	}
	@Override
	public void display(Interface out) throws IOException {
		out.print("<h2>题面</h2><br/><textarea name=\"" + getKey()  + "cont\">在此处输入题目</textarea>");
		out.print("<br/><h2>参考答案</h2><br/><textarea name=\"" + getKey()+ "ref\">在此处输入参考答案</textarea>");
	}
	@Override
	public void setValueViaInterface(Interface inf) {
		String value = inf.getValue(getKey() + "cont");
		content = value == null ? "" : value;
		value = inf.getValue(getKey() + "ref");
		reference = value == null ? "" : value;
	}
}










